#include "fupdate.h"
#if FUPDATE_USING_FASTLZ

#include <fastlz.h>


void *rbl_fastlz_decompress_context_create(void)
{
	void * fastlz_decom_ctx  = rt_calloc(1, 4);
	return fastlz_decom_ctx;
}
void rbl_fastlz_decompress_context_delete(void *fastlz_decom_ctx)
{
	rt_free(fastlz_decom_ctx);
}

uint32_t rbl_fastlz_decompress_get_block_size(void *fastlz_decom_ctx, const uint8_t *compress_datas)
{
  uint32_t block_size = 0;
  for (int i = 0; i < FUPDATE_FASTLZ_HEADER_SIZE; i++)
  {
    block_size <<= 8;
    block_size += compress_datas[i];
  }
  return (block_size);
}

uint32_t rbl_fastlz_decompress_data(void *fastlz_decom_ctx, uint8_t *out_buf, uint32_t out_buf_size, const uint8_t *in_buf, uint32_t block_size)
{
  return (fastlz_decompress(in_buf, block_size, out_buf, out_buf_size));
}

#endif
